package com.zg.common.core.dao.scf.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.common.core.dao.scf.entity.Rule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/5/21 20:49
 */
@Mapper
public interface RuleMapper extends BaseMapper<Rule> {

    @Select("<script>" +
            "SELECT conf.*, company.company_name as companyName FROM scf_rule conf " +
            "LEFT JOIN scf_company company ON company.id = conf.company_id " +
            "<where>" +
            "  company.is_del = 0 and conf.is_del=0" +
            "   <if test=\"companyName != null and ew.sqlSegment != ''\"> AND company.company_name LIKE '%' || #{companyName} || '%'</if>" +
            "  <if test=\"ew != null and ew.sqlSegment != ''\"> AND ${ew.sqlSegment}</if>" +
            "</where>" +
            "</script>")
    Page<Rule> page(Page<Rule> page,
                    @Param(Constants.WRAPPER) LambdaQueryWrapper<Rule> wrapper, @Param("companyName") String companyName);
}
